package graduation.project.testcase.strategy;

import graduation.project.body.OriginExpression;
import graduation.project.body.TestCase;
import graduation.project.body.TestCases;
import graduation.project.exception.NonExpressionException;

import java.util.ArrayList;
import java.util.LinkedHashSet;

public class MAXAGenerator implements TestSetGenerator {

	public TestCases generateTestCases(String expression, int testCaseNumber){		
		try {
			OriginExpression originEx;
			originEx = new OriginExpression(expression);
			return generateTestCases(originEx, testCaseNumber);
		} catch (NonExpressionException e) {
			System.out.println("the expression is not valid boolean expression");
			e.printStackTrace();
		}
		return null;
	}

	public TestCases generateTestCases(OriginExpression expression,	int testCaseNumber) {
		
		TestCases result = new TestCases(expression.getExpression(), expression.getModel(), "MAXA");
		LinkedHashSet<TestCase> testSet = new LinkedHashSet<TestCase>();
		
		int[][] utpSet = expression.getUtpSet();
		int[][][] nfpSet = expression.getNfpSet();
		
		TestCase tempTestC;
		for(int i = 0; i < utpSet.length; i++)
			for(int j = 0; j < utpSet[i].length; j++){
				tempTestC = new TestCase(utpSet[i][j], true);
				testSet.add(tempTestC);
			}
		
		for(int i = 0; i < nfpSet.length; i++){
			for(int j = 0; j < nfpSet[i].length; j++)
				for(int k = 0; k < nfpSet[i][j].length; k++){
					tempTestC = new TestCase(nfpSet[i][j][k], false);
					testSet.add(tempTestC);
				}
		}
		
		ArrayList<TestCase> set = new ArrayList<TestCase>();
		set.addAll(testSet);
		result.setTestSet(set);
		
		return result;
	}
}
